package labox.innovation.gameserver.datatables;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map.Entry;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javolution.util.FastMap;
import labox.innovation.config.Config;
import labox.innovation.gameserver.idfactory.GUIDFactory;
import labox.innovation.gameserver.model.ShopItem;
import labox.innovation.gameserver.model.actor.instance.FuzePcInstance;
import labox.innovation.gameserver.network.SystemMessageId;
import labox.innovation.gameserver.network.serverpackets.SystemMessage;
import labox.innovation.gameserver.templates.item.L2Item;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

/**
 * 商店出售物品列表
 * 
 * @author Frank
 * 
 */
public class ShopItemsListConfig {

	public static final Logger _log = LoggerFactory.getLogger(ShopItemsListConfig.class.getName());

	private static final ShopItemsListConfig _instance = new ShopItemsListConfig();

	private StringBuilder newItemPage = new StringBuilder();

	private StringBuilder hotSellPage = new StringBuilder();

	private StringBuilder discountPage = new StringBuilder();

	private StringBuilder dayPage = new StringBuilder();

	private StringBuilder materialPage = new StringBuilder();

	private StringBuilder pointPage = new StringBuilder();

	public static String SHOP_LIST;

	/** 新品 */
	public static final byte NEW_ITEM = 0;

	/** 热卖 */
	public static final byte HOT_SELL = 1;

	/** 打折 */
	public static final byte DISCOUNT_ITEM = 2;

	/** 日常 */
	public static final byte DAY_ITEM = 3;

	/** 材料 */
	public static final byte MATERIAL_ITEM = 4;

	/** 积分 */
	public static final byte POINT_ITEM = 5;

	/** 商品容器 */
	private FastMap<Long, ShopItem> itemsList = new FastMap<Long, ShopItem>();

	/**
	 * 初始化
	 */
	private void init() {
		newItemPage.append("	<tb ln='n' bt='1'>\n");
		newItemPage.append("		<tb ln='l' w='90%'>\n");
		newItemPage.append("		<tr h='5'><td></td></tr>\n");

		hotSellPage.append("	<form nm='hotsell' >\n");
		hotSellPage.append("	<tb ln='n' bt='1'>\n");
		hotSellPage.append("		<tb ln='l' w='90%'>\n");
		hotSellPage.append("		<tr h='5'><td></td></tr>\n");
		hotSellPage.append("				<tr h='5'><td></td></tr>\n");

		discountPage.append("	<form nm='discount' >\n");
		discountPage.append("	<tb ln='n' bt='1'>\n");
		discountPage.append("		<tb ln='l' w='90%'>\n");
		discountPage.append("		<tr h='5'><td></td></tr>\n");
		discountPage.append("				<tr h='5'><td></td></tr>\n");

		dayPage.append("	<form nm='day' >\n");
		dayPage.append("	<tb ln='n' bt='1'>\n");
		dayPage.append("		<tb ln='l' w='90%'>\n");
		dayPage.append("		<tr h='5'><td></td></tr>\n");
		dayPage.append("				<tr h='5'><td></td></tr>\n");

		materialPage.append("	<form nm='material' >\n");
		materialPage.append("	<tb ln='n' bt='1'>\n");
		materialPage.append("		<tb ln='l' w='90%'>\n");
		materialPage.append("		<tr h='5'><td></td></tr>\n");
		materialPage.append("				<tr h='5'><td></td></tr>\n");

		pointPage.append("	<form nm='point' >\n");
		pointPage.append("	<tb ln='n' bt='1'>\n");
		pointPage.append("		<tb ln='l' w='90%'>\n");
		pointPage.append("		<tr h='5'><td></td></tr>\n");
		pointPage.append("				<tr h='5'><td></td></tr>\n");
	}

	/**
	 * 组装结尾部分
	 */
	private void buildEnd() {
		newItemPage.append("		</tb>\n");
		newItemPage.append("	</tb>\n");
		newItemPage.append("    <s>\n");
		newItemPage.append("    sub click()\n");
		newItemPage.append("    popForm(\"newitem\",\"topmenu\")\n");
		newItemPage.append("    curVal= getFocusName(\"newitem\")\n");
		newItemPage.append("    num = getVal(curVal)\n");
		newItemPage.append("    name=getText(getFocusName(\"newitem\"))\n");
		newItemPage.append("    setCmd(\"topmenu.look\",\"send:113:b1:i\"+curVal)\n");
		newItemPage.append("    setVal(\"topmenu.buy\",\"send:129:l\"+num)\n");
		newItemPage.append("    ret\n");
		newItemPage.append("    </s>\n");

		hotSellPage.append("			</tb>\n");
		hotSellPage.append("	    </tb>\n");
		hotSellPage.append("    <s>\n");
		hotSellPage.append("    sub click()\n");
		hotSellPage.append("    popForm(\"newitem\",\"topmenu\")\n");
		hotSellPage.append("    curVal= getFocusName(\"hotsell\")\n");
		hotSellPage.append("    num = getVal(curVal)\n");
		hotSellPage.append("    name=getText(getFocusName(\"hotsell\"))\n");
		hotSellPage.append("    setCmd(\"topmenu.look\",\"send:113:b1:i\"+curVal)\n");
		hotSellPage.append("    setVal(\"topmenu.buy\",\"send:129:l\"+num)\n");
		hotSellPage.append("    ret\n");
		hotSellPage.append("    </s>\n");
		hotSellPage.append(" </form>\n");

		discountPage.append("			</tb>\n");
		discountPage.append("	    </tb>\n");
		discountPage.append("    <s>\n");
		discountPage.append("    sub click()\n");
		discountPage.append("    popForm(\"newitem\",\"topmenu\")\n");
		discountPage.append("    curVal= getFocusName(\"discount\")\n");
		discountPage.append("    num = getVal(curVal)\n");
		discountPage.append("    name=getText(getFocusName(\"discount\"))\n");
		discountPage.append("    setCmd(\"topmenu.look\",\"send:113:b1:i\"+curVal)\n");
		discountPage.append("    setVal(\"topmenu.buy\",\"send:129:l\"+num)\n");
		discountPage.append("    ret\n");
		discountPage.append("    </s>\n");
		discountPage.append(" </form>\n");

		dayPage.append("			</tb>\n");
		dayPage.append("	    </tb>\n");
		dayPage.append("    <s>\n");
		dayPage.append("    sub click()\n");
		dayPage.append("    popForm(\"newitem\",\"topmenu\")\n");
		dayPage.append("    curVal= getFocusName(\"day\")\n");
		dayPage.append("    num = getVal(curVal)\n");
		dayPage.append("    name=getText(getFocusName(\"day\"))\n");
		dayPage.append("    setCmd(\"topmenu.look\",\"send:113:b1:i\"+curVal)\n");
		dayPage.append("    setVal(\"topmenu.buy\",\"send:129:l\"+num)\n");
		dayPage.append("    ret\n");
		dayPage.append("    </s>\n");
		dayPage.append(" </form>\n");

		materialPage.append("			</tb>\n");
		materialPage.append("	    </tb>\n");
		materialPage.append("    <s>\n");
		materialPage.append("    sub click()\n");
		materialPage.append("    popForm(\"newitem\",\"topmenu\")\n");
		materialPage.append("    curVal= getFocusName(\"material\")\n");
		materialPage.append("    num = getVal(curVal)\n");
		materialPage.append("    name=getText(getFocusName(\"material\"))\n");
		materialPage.append("    setCmd(\"topmenu.look\",\"send:113:b1:i\"+curVal)\n");
		materialPage.append("    setVal(\"topmenu.buy\",\"send:129:l\"+num)\n");
		materialPage.append("    ret\n");
		materialPage.append("    </s>\n");
		materialPage.append(" </form>\n");

		pointPage.append("			</tb>\n");
		pointPage.append("	    </tb>\n");
		pointPage.append("    <s>\n");
		pointPage.append("    sub click()\n");
		pointPage.append("    popForm(\"newitem\",\"topmenu\")\n");
		pointPage.append("    curVal= getFocusName(\"point\")\n");
		pointPage.append("    num = getVal(curVal)\n");
		pointPage.append("    name=getText(getFocusName(\"point\"))\n");
		pointPage.append("    setCmd(\"topmenu.look\",\"send:113:b1:i\"+curVal)\n");
		pointPage.append("    setVal(\"topmenu.buy\",\"send:129:l\"+num)\n");
		pointPage.append("    ret\n");
		pointPage.append("    </s>\n");
		pointPage.append(" </form>\n");
	}

	/**
	 * 载入配置信息到内存
	 */
	public void loadConfig() {
		FileInputStream fs = null;
		long uid = 0;

		init();

		try {
			File f = new File(Config.DATAPACK_ROOT, "/data/shopItemsList.xml");
			DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
			DocumentBuilder builder = factory.newDocumentBuilder();
			fs = new FileInputStream(f);
			Document document = builder.parse(fs);
			Element root;
			root = document.getDocumentElement();

			if (root.getTagName().compareTo("List") != 0) {
				throw new Exception("Not a shopItemsList file!");
			}

			Element parentNode = null;
			Element childNode = null;
			NodeList childList = null;
			NodeList list = root.getElementsByTagName("Type");

			for (int i = 0; i < list.getLength(); i++) {
				parentNode = (Element) list.item(i);
				byte type = Byte.parseByte(parentNode.getAttribute("id"));
				String value = parentNode.getAttribute("value");
				childList = parentNode.getElementsByTagName("Items");

				for (int j = 0; j < childList.getLength(); j++) {
					childNode = (Element) childList.item(j);

					if (childNode.getAttribute("id") == null || "".equals(childNode.getAttribute("id").trim())) {
						continue;
					}

					ShopItem item = new ShopItem();
					uid = GUIDFactory.getInstance().getNextId(GUIDFactory.ID_MERCHANDISE);
					item.setUid(uid);
					item.setType(type);
					item.setTypeValue(value);
					item.setId(Integer.parseInt(childNode.getAttribute("id")));
					item.setPrice(Integer.parseInt(childNode.getAttribute("price")));
					item.setPriceOfPoint(Integer.parseInt(childNode.getAttribute("priceOfPoint")));
					item.setDiscountPrice(Integer.parseInt(childNode.getAttribute("discountPrice")));
					item.setPointOfPresent(Integer.parseInt(childNode.getAttribute("pointOfPresent")));
					addItem(item);
					addPage(item);
				}
			}

			_log.info("从商城物品模板获取了" + uid + "条商品信息", Config.SERVER_ID, "商城系统");

			buildEnd();
			SHOP_LIST = buildPacket();
		} catch (Exception e) {
			_log.error("load shopItemListConfig error", Config.SERVER_ID, e);
			e.printStackTrace();
		} finally {
			try {
				fs.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

	/**
	 * 增加记录
	 * 
	 * @param item
	 */
	private void addItem(ShopItem item) {
		itemsList.put(item.getUid(), item);
	}

	/**
	 * 根据商店物品买卖类别获取商店物品列表<br>
	 * 
	 * @param type
	 *            0:新品;1:热卖 ;2:打折;3:日常;4:材料;5:积分
	 * @return
	 */
	public FastMap<Integer, ShopItem> getShopListByType(byte type) {
		FastMap<Integer, ShopItem> result = new FastMap<Integer, ShopItem>();
		int itemID;
		byte mType;
		Iterator<Entry<Long, ShopItem>> en = itemsList.entrySet().iterator();

		while (en.hasNext()) {
			Entry<Long, ShopItem> e = en.next();
			ShopItem item = e.getValue();
			itemID = item.getId();
			mType = item.getType();

			if (mType == type) {
				result.put(itemID, item);
			}
		}

		return result;
	}

	/**
	 * 根据物品模板ID获取商城物品信息
	 * 
	 * @param itemId
	 * @return
	 */
	public ShopItem getShopItem(int itemId) {
		ShopItem result = null;
		Iterator<Entry<Long, ShopItem>> en = itemsList.entrySet().iterator();

		while (en.hasNext()) {
			Entry<Long, ShopItem> e = en.next();

			if (itemId == e.getValue().getId()) {
				result = e.getValue();
				break;
			} else {
				continue;
			}
		}

		return result;
	}

	/**
	 * 根据元宝买物品
	 * 
	 * @param player
	 * @param item
	 * @param count
	 * @param price
	 */
	private void buyItemByMoney(FuzePcInstance player, ShopItem item, int count, int price) {
		int itemID = item.getId();

		if (player.getInventory().validateCapacityByItemId(itemID, count)) {
			int money = price * count;

			if (player.getMoneyYuanBao() >= money) {
				player.addItem("", itemID, count, player, true);
				player.reduceMoneyYuanBao("", money, player, true);
				player.sendPacket(new SystemMessage(SystemMessageId.TRADE_SUCCESSFUL)); //-- 交易成功

				if (item.getPointOfPresent() > 0) { //-- 赠送积分
					player.addMoneyPoint("", item.getPointOfPresent() * count, player, true);
				}
			} else {
				player.sendPacket(new SystemMessage(SystemMessageId.NO_ENOUGH_YUANBAO)); //-- 元宝不够
			}
		} else {
			player.sendPacket(new SystemMessage(SystemMessageId.INVENTORY_IS_FULL)); //-- 背包满
		}
	}

	/**
	 * 根据积分购买物品
	 * 
	 * @param player
	 * @param item
	 * @param count
	 * @param price
	 */
	private void buyItemByPoint(FuzePcInstance player, ShopItem item, int count, int price) {
		int itemID = item.getId();

		if (player.getInventory().validateCapacityByItemId(itemID, count)) {
			int money = price * count;

			if (player.getMoneyPoint() >= money) {
				player.addItem("", itemID, count, player, true);
				player.reduceMoneyPoint("", money, player, true);
				player.sendPacket(new SystemMessage(SystemMessageId.TRADE_SUCCESSFUL)); //-- 交易成功

				if (item.getPointOfPresent() > 0) { //-- 赠送积分
					player.addMoneyPoint("", item.getPointOfPresent() * count, player, true);
				}
			} else {
				player.sendPacket(new SystemMessage(SystemMessageId.NO_ENOUGH_POINT)); //-- 积分不够
			}
		} else {
			player.sendPacket(new SystemMessage(SystemMessageId.INVENTORY_IS_FULL)); //-- 背包满
		}
	}

	/**
	 * 接口方法；根据物品模板ID购买物品
	 * 
	 * @param player
	 * @param itemId
	 * @param count
	 */
	public void buyItemByItemId(FuzePcInstance player, Integer itemId, int count) {
		ShopItem item = getShopItem(itemId);

		if (item == null)
			return;

		int price = 0;

		switch (item.getType()) {
		case NEW_ITEM:
		case HOT_SELL:
		case DAY_ITEM:
		case MATERIAL_ITEM:
			price = item.getPrice();
			buyItemByMoney(player, item, count, price);
			break;
		case DISCOUNT_ITEM:
			price = item.getDiscountPrice();
			buyItemByMoney(player, item, count, price);
			break;
		case POINT_ITEM:
			price = item.getPriceOfPoint();
			buyItemByPoint(player, item, count, price);
			break;
		}
	}

	/**
	 * 
	 * @param uid
	 * @return
	 */
	public ShopItem getShopItem(long uid) {
		return itemsList.get(uid);
	}

	private ShopItemsListConfig() {
		loadConfig();
	}

	public static final ShopItemsListConfig getInstance() {
		return _instance;
	}

	/**
	 * 组装用户界面脚本
	 * 
	 * @param item
	 */
	private void addPage(ShopItem item) {

		switch (item.getType()) {
		case NEW_ITEM:
			addNewItemPage(item);
			break;
		case HOT_SELL:
			addHotSellPage(item);
			break;
		case DISCOUNT_ITEM:
			addDiscountPage(item);
			break;
		case DAY_ITEM:
			addDay(item);
			break;
		case MATERIAL_ITEM:
			addMaterial(item);
			break;
		case POINT_ITEM:
			addPoint(item);
			break;
		default:
			break;
		}
	}

	/**
	 * 新品
	 * 
	 */
	private void addNewItemPage(ShopItem item) {
		int itemID = item.getId();
		long uid = item.getUid();
		L2Item mItem = ItemTable.getInstance().getTemplate(itemID);
		if (mItem != null) {
			int itemIconID = mItem.getItemIconId();
			String itemName = mItem.getName();
			newItemPage.append("	    <tr>\n");
			newItemPage.append("         <td w = '20'><a pic = '82'></a></td>\n");
			newItemPage.append("         <td w = '50%'><a pic = '").append(itemIconID).append("' nm = '").append(itemID).append("' val = '").append(uid).append("' cmd ='' oc='click()' >").append(itemName).append("</a></td>\n");
			newItemPage.append("         <td><a pic = '89'>").append(item.getPrice()).append("</a></td>\n");
			newItemPage.append("     </tr>\n");
		} else {
			_log.info("物品模板中不存在编号为：" + itemID + "的物品！", Config.SERVER_ID, "商城系统");
		}
	}

	/**
	 * 热卖
	 * 
	 */
	private void addHotSellPage(ShopItem item) {
		int itemID = item.getId();
		long uid = item.getUid();
		L2Item mItem = ItemTable.getInstance().getTemplate(itemID);

		if (mItem != null) {
			int itemIconID = mItem.getItemIconId();
			String itemName = mItem.getName();
			hotSellPage.append("	    <tr>\n");
			hotSellPage.append("         <td w = '20'><a pic = '83'></a></td>\n");
			hotSellPage.append("         <td w = '50%'><a pic = '").append(itemIconID).append("' nm = '").append(itemID).append("' val = '").append(uid).append("' cmd ='' oc='click()' >").append(itemName).append("</a></td>\n");
			hotSellPage.append("         <td><a pic = '89'>").append(item.getPrice()).append("</a></td>\n");
			hotSellPage.append("     </tr>\n");
		} else {
			_log.info("物品模板中不存在编号为：" + itemID + "的物品！", Config.SERVER_ID, "商城系统");
		}
	}

	/**
	 * 打折
	 * 
	 */
	private void addDiscountPage(ShopItem item) {
		int itemID = item.getId();
		long uid = item.getUid();
		L2Item mItem = ItemTable.getInstance().getTemplate(itemID);

		if (mItem != null) {
			int itemIconID = mItem.getItemIconId();
			String itemName = mItem.getName();
			discountPage.append("	    <tr>\n");
			discountPage.append("         <td w = '20'><a pic = '84'></a></td>\n");
			discountPage.append("         <td w = '40%'><a pic = '").append(itemIconID).append("' nm = '").append(itemID).append("' val = '").append(uid).append("' cmd ='' oc='click()' >").append(itemName).append("</a></td>\n");
			discountPage.append("         <td w = '50%'><a pic = '89'>").append(item.getDiscountPrice()).append("(原价:").append(item.getPrice()).append(")</a></td>\n");
			discountPage.append("     </tr>\n");
		} else {
			_log.info("物品模板中不存在编号为：" + itemID + "的物品！", Config.SERVER_ID, "商城系统");
		}
	}

	/**
	 * 日常
	 * 
	 */
	private void addDay(ShopItem item) {
		int itemID = item.getId();
		long uid = item.getUid();
		L2Item mItem = ItemTable.getInstance().getTemplate(itemID);

		if (mItem != null) {
			int itemIconID = mItem.getItemIconId();
			String itemName = mItem.getName();
			dayPage.append("	    <tr>\n");
			dayPage.append("         <td w = '60%'><a pic = '").append(itemIconID).append("' nm = '").append(itemID).append("' val = '").append(uid).append("' cmd ='' oc='click()' >").append(itemName).append("</a></td>\n");
			dayPage.append("         <td><a pic = '89'>").append(item.getPrice()).append("</a></td>\n");
			dayPage.append("     </tr>\n");
		} else {
			_log.info("物品模板中不存在编号为：" + itemID + "的物品！", Config.SERVER_ID, "商城系统");
		}
	}

	/**
	 * 材料
	 * 
	 */
	private void addMaterial(ShopItem item) {
		int itemID = item.getId();
		long uid = item.getUid();
		L2Item mItem = ItemTable.getInstance().getTemplate(itemID);

		if (mItem != null) {
			int itemIconID = mItem.getItemIconId();
			String itemName = mItem.getName();
			materialPage.append("	    <tr>\n");
			materialPage.append("         <td w = '60%'><a pic = '").append(itemIconID).append("' nm = '").append(itemID).append("' val = '").append(uid).append("' cmd ='' oc='click()' >").append(itemName).append("</a></td>\n");
			materialPage.append("         <td><a pic = '89'>").append(item.getPrice()).append("</a></td>\n");
			materialPage.append("     </tr>\n");
		} else {
			_log.info("物品模板中不存在编号为：" + itemID + "的物品！", Config.SERVER_ID, "商城系统");
		}
	}

	/**
	 * 积分
	 * 
	 */
	private void addPoint(ShopItem item) {
		int itemID = item.getId();
		long uid = item.getUid();
		L2Item mItem = ItemTable.getInstance().getTemplate(itemID);

		if (mItem != null) {
			int itemIconID = mItem.getItemIconId();
			String itemName = mItem.getName();
			pointPage.append("	    <tr>\n");
			pointPage.append("         <td w = '60%'><a pic = '").append(itemIconID).append("' nm = '").append(itemID).append("' val = '").append(uid).append("' cmd ='' oc='click()' >").append(itemName).append("</a></td>\n");
			pointPage.append("         <td><a pic = '92'>").append(item.getPriceOfPoint()).append("</a></td>\n");
			pointPage.append("     </tr>\n");
		} else {
			_log.info("物品模板中不存在编号为：" + itemID + "的物品！", Config.SERVER_ID, "商城系统");
		}
	}

	public String buildPacket() {
		StringBuilder sb = new StringBuilder();
		sb.append("<form nm='newitem' tl='商城列表'>\n");
		sb.append("    <tag>\n");
		sb.append("	   <a cmd='' val='newitem'>新品</a>\n");
		sb.append("	   <a cmd='' val='hotsell'>热卖</a>\n");
		sb.append("	   <a cmd='' val='discount'>打折</a>\n");
		sb.append("	   <a cmd='' val='day'>日常</a>\n");
		sb.append("	   <a cmd='' val='material'>材料</a>\n");
		sb.append("	   <a cmd='' val='point'>积分</a>\n");
		sb.append("    </tag>\n");

		sb.append(newItemPage);
		sb.append(hotSellPage);
		sb.append(discountPage);
		sb.append(dayPage);
		sb.append(materialPage);
		sb.append(pointPage);

		sb.append("    <form nm='topmenu' w='65' h='106' pl='fw'>\n");
		sb.append("	       <tb ln='l'>\n");
		sb.append("	           <tr><td><a nm='look' cmd='' pl='min' oc='back()' hk='1'>查看</a></td></tr>\n");
		sb.append("	           <tr><td><a nm='buy' cmd='' pl='min' oc='openinput0()' hk='2'>购买</a></td></tr>\n");
		sb.append("	           <tr><td><a nm='present' pl='min' c = 'FFFFFF' oc='back()' hk='3'>赠送</a></td></tr>\n");
		sb.append("	           <tr><td><a nm='demand' pl='min' c = 'FFFFFF' oc='back()' hk='4'>索要</a></td></tr>\n");
		sb.append("	           <tr><td><a cmd='' hk='5' pl='min' oc='back()'>关闭</a></td></tr>\n");
		sb.append("	       </tb>\n");
		sb.append("        <form nm='takeinput' w='100' h='55'>\n");
		sb.append("            输入数量<br/>\n");
		sb.append("        <i nm='takenum' t='n' len='99'/>\n");
		sb.append("        <a cmd='' oc='takesure()'>确定 </a>\n");
		sb.append("        <s>\n");
		sb.append("            sub takesure()\n");
		sb.append("            action(getVal(\"topmenu.buy\")+\":i\"+getIS(\"takenum\"))\n");
		sb.append("            back()\n");
		sb.append("            back()\n");
		sb.append("            ret\n");
		sb.append("        </s>\n");
		sb.append("        </form>\n");
		sb.append("        <s>\n");
		sb.append("        sub openinput0()\n");
		sb.append("        popForm(\"topmenu\",\"takeinput\")\n");
		sb.append("        ret\n");
		sb.append("        </s>\n");

		sb.append("    </form>\n");
		sb.append("</form>\n");

		return sb.toString();
	}

	public static void main(String args[]) {
		ShopItemsListConfig cf = ShopItemsListConfig.getInstance();

		FastMap<Integer, ShopItem> fs = cf.getShopListByType((byte) 0);

		Iterator<Entry<Integer, ShopItem>> en = fs.entrySet().iterator();
		while (en.hasNext()) {
			Entry<Integer, ShopItem> item = en.next();
			System.out.println(item.getKey());
			System.out.println(item.getValue());
		}
	}
}
